package com.winxuan.channel.controller.commodity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.validation.Valid;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.winxuan.channel.controller.commodity.form.TtForm;
import com.winxuan.channel.support.interceptor.PaginationAware;
import com.winxuan.channel.support.view.excel.ExcelView;
import com.winxuan.util.pagination.Pagination;

@Controller
@RequestMapping(value="/test")
public class TT implements PaginationAware{
	
	private Pagination pagination;

	@RequestMapping(value="/valid",method = RequestMethod.GET)
	public ModelAndView get(final ModelMap model) {
		ModelAndView modelAndView = new ModelAndView("/user");
		TtForm ttForm = new TtForm();
		model.addAttribute("ttForm", ttForm);
		return modelAndView;
	}


	@RequestMapping(value="/valid",method = RequestMethod.POST)
	public ModelAndView getDef(ModelMap model,@Valid TtForm ttForm,BindingResult result){
		ModelAndView modelAndView = new ModelAndView();
		if(result.hasErrors()){
			System.out.println("Error");
			modelAndView.setViewName("/user");
		}else{
			System.out.println("C:"+ttForm.getName());
			modelAndView.setViewName("/result");
			System.out.println("Right");			
		}
		return modelAndView;
	}
	
	@RequestMapping(value="/excel",method = RequestMethod.GET)
	public ModelAndView getExcel(){
		List<String> list = new ArrayList<String>();   
        Map model = new HashMap();   
        list.add("test1");   
        list.add("test2");   
        model.put("list", list);   
        model.put("name", "HideHai");
        System.out.println(pagination.getCurrentPage());
        pagination.setPageSize(30);
        pagination.setCount(1000);
        model.put("pagination", pagination);
        return new ModelAndView("tag",model); 
	}


	@Override
	public void setPagination(Pagination pagination) {
		this.pagination = pagination;
	}

}
